class Solution
{
public:
    int lengthOfLastWord(string s)
    {
        int back = s.size() - 1;
        while (s[back] == ' ')
        {
            --back;
        }
        int front = back;
        while (front >= 0 && s[front] != ' ')
        {
            --front;
        }
        return back - front;
    }
};